package com.zhuss.meeting.processor;

import com.zhuss.bean.bo.meeting.apply.SearchApplyBo;
import com.zhuss.bean.bo.meeting.apply.SearchCheckBo;
import com.zhuss.bean.bo.meeting.room.GetSituationBo;
import com.zhuss.bean.vo.meeting.apply.ListApplyStatusVo;
import com.zhuss.bean.vo.meeting.apply.ListApplyVo;
import com.zhuss.bean.vo.meeting.apply.RoomNameVo;
import com.zhuss.bean.vo.meeting.room.PercentageRoomVo;
import com.zhuss.common.AbstractBo;
import com.zhuss.common.PageVo;
import com.zhuss.exception.WpsException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.meeting.db.dao.ext.MeetingApplyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhushanshuo
 * @Date: 2020/2/25 16:27
 */
@Component("applyRead")
public class ApplyRead {

    @Autowired
    private MeetingApplyDao meetingApplyDao;

    /**
     * 用户列表
     * @return
     */
    public Object list(SearchApplyBo bo) {
        PageVo<ListApplyVo> result = new PageVo<ListApplyVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(meetingApplyDao.list(bo));
        result.setTotal(meetingApplyDao.countList(bo));
        return result;
    }

    /**
     * 用户详情
     * @param applyId
     * @throws WpsException
     */
    public Object detail(Long applyId) throws WpsException {
        Object result = meetingApplyDao.detail(applyId);
        if (result == null) {
            throw new WpsException(ExceptionCode.数据不存在);
        }
        return result;
    }

    /**
     * 会议室待审批列表
     * @return
     */
    public Object listCheck(SearchCheckBo bo) {
        PageVo<ListApplyVo> result = new PageVo<ListApplyVo>();
//        bo.setStatus(MeetRoomCheck.待审核.key());
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(meetingApplyDao.listCheck(bo));
        result.setTotal(meetingApplyDao.countListCheck(bo));
        return result;
    }

    /**
     * 会议室已审批列表
     * @return
     */
    public Object listApproved(SearchCheckBo bo) {
        PageVo<ListApplyVo> result = new PageVo<ListApplyVo>();
//        bo.setStatus(MeetRoomCheck.已审核.key());
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(meetingApplyDao.listApproved(bo));
        result.setTotal(meetingApplyDao.countListCheck(bo));
        return result;
    }

    /**
     * 获取会议室百分比
     * @param o
     * @return
     */
    public List<PercentageRoomVo> getRoomPercentage(AbstractBo o){
        List<PercentageRoomVo> percentageList = new ArrayList<>();
        Integer area = o.getConcurrentArea();
        List<RoomNameVo> roomNameList = meetingApplyDao.getMeetingRoomName(area);
        int count = 0;
        for (RoomNameVo roomNameVo : roomNameList){
            count += roomNameVo.getNumber();
        }
        for (RoomNameVo roomNameVo : roomNameList){
            PercentageRoomVo percentage = new PercentageRoomVo();
            percentage.setName(roomNameVo.getRoomName());
            percentage.setY((float)roomNameVo.getNumber()/(float)count* 100);
            percentageList.add(percentage);
        }
        return percentageList;
    }

    /**
     * 获取会议室状态
     * @param bo
     * @return
     */
    public Object getRoomStatus(GetSituationBo bo) {
        List<ListApplyStatusVo> result = new ArrayList<>();
        result = meetingApplyDao.roomStatusList(bo);
        return result;
    }
}
